import Vue from 'vue'
const job = {
  // 获取附带状态的任务列表
  getList: function getList(ip, postdata) {
    var ipPath = ip + '/' + postdata.pageNo + '/' + postdata.pageSize + '/' + postdata.state
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 获取完成或者删除任务列表
  getAllList: function getAllList(ip, postdata) {
    var ipPath = ip + '/' + postdata.pageNum + '/' + postdata.pageSize
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 获取cron任务列表
  getCronList: function getCronList(ip, postdata) {
    var ipPath = ip + '/' + postdata.pageNo + '/' + postdata.pageSize
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 任务-添加任务
  addJob: function addJob(ip, postdata) {
    console.log(ip, postdata)
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 任务-终止任务
  cancelJobFun: function cancelJobFun(ip, postdata) {
    console.log(ip, postdata)
    var ipPath = ip + '/' + postdata.eventId
    return Vue.http.post(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 任务-删除任务
  delJobFun: function delJobFun(ip, postdata) {
    console.log(ip, postdata)
    var ipPath = ip + '/' + postdata.jobId
    return Vue.http.post(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 任务-task任务
  taskJobFun: function taskJobFun(ip, postdata) {
    var ipPath = ip + '/' + postdata.pageNum + '/' + postdata.pageSize + '?jobId=' + postdata.jobId
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  }
}

export default job
